import { render, Component } from "inferno";
import Login from "./Login";
import Matrix from "./Matrix";
import * as localforage from "localforage";
import { setPushGateway } from "./utils";
import "./index.css";

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      login: null,
    };
    localforage.getItem("login").then((login) => {
      this.setState({ login: login });
    });
  }

  componentWillMount() {
    if (!window.navigator.onLine) {
      window.alert("Sorry but I cannot work without the Internet!");
      window.close();
    }
  }

  render() {
    if (this.state.login === null) {
      return <Login />;
    } else {
      return <Matrix login={this.state.login} />;
    }
  }
}

setPushGateway();
render(<App />, document.getElementById("root"));
